import click
import os
from loguru import logger
from tqdm import tqdm
import pickle as pk


@click.command()
@click.option("-p", "--path", type=str, help="The dir path for merging data")
@click.option("-n", "--name", type=str, help="The save name")
def run(path, name):

    if not os.path.exists(path):
        logger.error("No such a dir!")

    data = {}
    for file_name in tqdm(os.listdir(path)):
        with open("{}/{}".format(path, file_name), "rb") as f:
            tmp_data = pk.load(f)
            data[file_name[:-4]] = tmp_data

    logger.info("Saving data ...")
    with open(name, "wb") as f:
        pk.dump(data, f)


if __name__ == "__main__":
    run()
